package com.example.manager.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.manager.entity.Course;
import com.example.manager.service.CourseService;

@RestController
public class CourseController {
	
	@Autowired
	private CourseService service;
	
	@GetMapping("courses")
	public List<Course> getAllCourses(){
		return service.findAllCourse();
	}
	
	@GetMapping("coursesByCode/{code}")
	public Course getCourseById(@PathVariable String code) {
		return service.getByCode(code);
	}
	
	@GetMapping("coursesById/{id}")
	public Course getById(@PathVariable Integer id) {
		return service.getById(id);
	}
	
	@PostMapping("courses")
	public String addCourse(Course course) {
		return service.addCourse(course);
	}
	
	@PutMapping("courses/{id}")
	public String editCourse(Course course, @PathVariable Integer id) {
		course.setId(id);
		return service.editCourse(course);
	}
	
	@DeleteMapping("courses/{id}")
	public String delCourse(@PathVariable Integer id) {
		return service.deleteCourse(id);
	}
	
}
